// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool check_valid(int x)
{
	int y=x/10000;
	int m=x%10000/100;
	int d=x%100;
	if(d==0||m==0||m>12)return 0;
	if(m!=2&&d>months[m])return 0;
	if(m==2)
	{
		if((y%4==0&&y%100!=0)||(y%400==0))
		{
			if(d>29)return 0;
		}
		else if(d>28)return 0;
	}
	return 1;
}
bool check1(int x)
{
	string s=to_string(x);
	string rs=s;
	reverse(s.begin(),s.end());
	return s==rs;
}
bool check2(int x)
{
	string s=to_string(x);
	string rs=s;
	reverse(s.begin(),s.end());
	return s==rs&&s[0]==s[2]&&s[1]==s[3];
}
signed main()
{
	int t=1;
//	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		bool f1=0,f2=0;
		for(int i=n+1;i<=92200229;i++)
		{
			if(check_valid(i))
			{
				if(!f1&&check1(i))
				{
					f1=1;
					cout<<i<<endl;
				}
				if(!f2&&check2(i))
				{
					f2=1;
					cout<<i<<endl;
				}
			}
			if(f2)break;
		}
	}
	return 0;
}
